import http from './http'

// 流程定义管理
export const processDefinitionApi = {
  // 获取流程定义列表
  getList: (params) => http.get('/workflow/repository/processDefinition/list', params),
  // 获取流程定义列表
  options: (params) => http.get('/workflow/repository/processDefinition/options', params),
  // 导入流程
  import: (formData) =>
    http.post('workflow/repository/processDefinition/deployment/create', formData),
  // 获取流程XML
  getXml: (id) =>
    http.get(`/workflow/repository/processDefinition/bpmn`, { processDefinitionKey: id }),
  // 批量删除流程定义
  batchDelete: (params) => http.delete('/workflow/repository/processDefinition', params),
  // 修改状态
  updateState: (params) => http.put('/workflow/repository/processDefinition/state', params)
}

// 流程实例管理
export const processInstanceApi = {
  // 启动实例
  startProcess: (params) => http.post('workflow/runtime/processInstance/start', params),
  // 获取流程实例列表
  getList: (params) => http.get('/workflow/runtime/processInstance/list', params),
  // 激活流程实例
  activate: (id) => http.put(`/workflow/runtime/processInstance/${id}/activate`),
  // 挂起流程实例
  suspend: (id) => http.put(`/workflow/runtime/processInstance/${id}/suspend`),
  // 删除流程实例
  delete: (id) => http.delete(`/workflow/runtime/processInstance/${id}`)
}

// 任务管理
export const taskApi = {
  // 获取任务列表
  getList: (params) => http.get('/workflow/task/list', params),
  // 获取任务流程图
  getDiagram: (id) => http.get(`/workflow/task/diagram/${id}`),
  // 签收任务
  claim: (id) => http.post(`/workflow/task/claim/${id}`),
  // 完成任务
  complete: (id) => http.post(`/workflow/task/complete/${id}`),
  // 委派任务
  delegate: (data) => http.post('/workflow/task/delegate', data)
}

// 历史管理
export const historyApi = {
  // 获取历史列表
  getList: (params) => http.get('/workflow/history/list', params),
  // 获取历史流程图
  getDiagram: (processInstanceId) => http.get(`/workflow/history/diagram/${processInstanceId}`),
  // 获取流程跟踪
  getTrace: (processInstanceId) => http.get(`/workflow/history/trace/${processInstanceId}`)
}

// 系统用户
export const systemApi = {
  // 获取用户列表
  getUserList: () => http.get('/system/user/list')
}
